<?php 
	include ("../../config/koneksi.php");
	$provinsi = "$_POST[provinsi]";
	if($provinsi == "all"){
		$q = "select * from kabupaten k inner join propinsi p on k.id_propinsi = p.id_propinsi where k.aktif = 'Y' and p.aktif = 'Y'";
		$r = mysql_query($q);
		$content = "DAFTAR KABUPATEN\n\nNO;KODE;KABUPATEN;PROVINSI\n";
		while ($data = mysql_fetch_array($r)) {
			$no++;
			$content .= "$no;$data[id_kabupaten];$data[kabupaten];$data[propinsi]\n";
		};
	}else{
		$q = "select * from kabupaten where id_propinsi=$provinsi and aktif = 'Y'";
		$r = mysql_query($q);
		$prov = mysql_fetch_array(mysql_query("select propinsi from propinsi where id_propinsi = $provinsi"));
		$content = "DAFTAR KABUPATEN DI ".strtoupper($prov['propinsi'])."\n\nNO;KODE;KABUPATEN\n";
		while ($data = mysql_fetch_array($r)) {
			$no++;
			$content .= "$no;$data[id_kabupaten];$data[kabupaten]\n";
		};
	}

	header("Content-type: text/csv");
	header("Content-Disposition: attachment; filename=kabupaten.csv");
	header("Pragma: no-cache");
	header("Expires: 0");
	echo $content;

?>